import { getToken } from "@/utils/token"
import { getUname } from "@/utils/uname"
import { getRole } from "@/utils/role"
import { getMenu } from "@/utils/menu"
import { getList } from "@/utils/list"

export default {
  getters: {
    token: ({ user }) => {
      return user.token || getToken()
    },
    username: ({ user }) => {
      return user.username || getUname()
    },
    role: ({ user }) => {
      return user.role || getRole()
    },
    menu: ({ user }) => {
      // console.log("user.menu", user.menu);
      // console.log("getMenu()", getMenu());
      if (user.menu.length > 0) {
        return user.menu
      } else {
        return getMenu()
      }
    },
    list: ({ admin }) => {
      if (admin.list.length > 0) {
        return admin.list
      } else {
        return getList()
      }
    },
  }
}